#include <iostream>
using namespace std;

const int kMaxN = 510;

int num[kMaxN][kMaxN], tmp[kMaxN][kMaxN];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;

  cin >> n >> m;
  for (int i = 0, flag = 1; i < n; i++) {
    for (int j = 0; j < n; j++, flag++) {
      num[i][j] = flag;
    }
  }
  for (; m; m--) {
    int x, y, r, z;
    cin >> x >> y >> r >> z;
    x--, y--;
    for (int i = x - r; i <= x + r; i++) {
      for (int j = y - r; j <= y + r; j++) {
        tmp[i][j] = num[i][j];
      }
    }
    if (z == 0) {
      for (int i = x - r, k = y + r; i <= x + r; i++, k--) {
        for (int j = y - r, l = x - r; j <= y + r; j++, l++) {
          num[l][k] = tmp[i][j];
        }
      }
    } else {
      for (int i = x - r, k = y - r; i <= x + r; i++, k++) {
        for (int j = y - r, l = x + r; j <= y + r; j++, l--) {
          num[l][k] = tmp[i][j];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << num[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}